package com.sharkpro.designPattern.myIO;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
 * @author jianxin.wei
 * @description 使用hutool中的IO工具类
 * @date 2024/12/18 15:20
 */
@Slf4j
public class HutoolIO {

    private static final String FILENAME = "C:/Users/xiechang/Desktop/cur.txt";

    public static void main(String[] args) {
        String read = FileUtil.readUtf8String(FILENAME);
        JSONObject object = JSONUtil.parseObj(read);
        JSONArray jsonArray = object.getJSONObject("data").getJSONArray("dateList");
        DateTime now = DateUtil.date(new Date());
        Integer nowDD = Integer.valueOf(DateUtil.format(now, "dd"));
        DateTime begin = DateUtil.beginOfMonth(now);
        Integer beginDD = Integer.valueOf(DateUtil.format(now, "dd"));

        JSONArray array = new JSONArray();
        for (int i = 1; i < nowDD; i++) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.set("ping",i);
            jsonObject.set("feng",i);
            jsonObject.set("jian",i);
            jsonObject.set("gu",i);
            jsonObject.set("total",4*i);
            jsonObject.set("day" , "2024-12-"+i);
            array.set(jsonObject);
        }
        object.getJSONObject("data").set("dateList",array);
        read=object.toString();
        FileUtil.writeUtf8String(read,FILENAME);

        System.out.println(object);

    }
}
